/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beanControl;

import Utils.Helper;
import Utils.JDBCHelper;
import Utils.StringUtility;
import beanInfo.purposes;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTable;

/**
 *
 * @author lyan
 */
public class purposesControl {

    ArrayList<String> listColumn = new ArrayList<String>();
    ArrayList<String> listValue = new ArrayList<String>();
    purposes pu = new purposes();

    public void listpurposes(JTable table) {
        String sql = "select * from Purposes";
        String[] header = {"PurposesID", "InterestID", "objectLoan", "Years", "Status"};
        Helper.loadDataTable(sql, table, header);
    }

    public void insertPurpose(purposes pu) {
        Object[] values = { pu.getObjectLoan(),
            pu.getYears(), pu.getStatus()};
        JDBCHelper.excuteInsertPlaceHolder("Purposes", 3, values);
        Helper.successMessage("Insert  successfull", "wanning");
    }

    public void updatepurposes(purposes pu) {
        String[] objColumn = {"objectLoan"," Years"," Status"};
        String[] objValues = {  pu.getObjectLoan(),
            String.valueOf(pu.getYears()), pu.getStatus()};

        listColumn = (ArrayList<String>) StringUtility.ArrayToArrayList(objColumn);
        listValue = (ArrayList<String>) StringUtility.ArrayToArrayList(objValues);
        JDBCHelper.executeUpdate("Purposes", listColumn, listValue, "PurposesID", String.valueOf(pu.getPurposesID()));
        Helper.successMessage("Update Sucessful", "wanning");
    }

    public void Deletepurposes(purposes cus) {

        {
            JDBCHelper.excuteDelete("Purposes", "PurposesID", String.valueOf(pu.getPurposesID()));
            Helper.successMessage("Delete successfull", "wanning");
        }

    }

  
}
